import { render, createVNode } from 'vue'
import Loading from './loading.vue'
 
let vm
// 使用单例模式，不再重新插入body
function getLoadingInstance () {
  if (vm) return
  const div = document.createElement('div')
  vm = createVNode(Loading)
  render(vm, div)
  document.body.appendChild(div)
}
 
export default function loading ( duration) {
  getLoadingInstance()
  vm.component.exposed?.open({
    duration
  })
}